<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{if $operFlg == 2}-->
        <title>商品闪购添加</title>
    <!--{else}-->
        <title>商品闪购修改</title>
    <!--{/if}-->
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">
        <h2>
            <!--{if $operFlg == 2}-->
            商品闪购添加
            <!--{else}-->
            商品闪购修改
            <!--{/if}-->
        </h2>

        <div class="items2">

            <form id="s_form">
            
            	<div class="input-group input-group-lg">
	                <span class="input-group-addon">商家编码：</span>
		                <span style="padding-left:10px;" class="input-group-radio">
		                <input type="text" style="padding-left:10px;" value="<!--{$seckill_array.product_code|default:''}-->" id="product_code" name="product_code" >
		                <input type="hidden" name="kill_id" value="<!--{$seckill_array.kill_id|default:''}-->" >
		                &nbsp;&nbsp;
	                	<input type="button" value="查询" id="search_goods" class="btn" onclick="S.goods.search();" >
                	</span>
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">商品名称：</span>
	                <span style="padding-left:10px;" disabled="" class="form-control hasDatepicker" id="goodsName"><!--{$seckill_array.goodsName|default:''}--></span>
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">销售价：</span>
	                <span style="padding-left:10px;" disabled="" class="form-control hasDatepicker" id="salePrice"><!--{$seckill_array.salePrice|default:''}--></span>
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">闪购价：</span>
	                <input type="text" style="padding-left:10px;" value="<!--{$seckill_array.kill_price|default:''}-->" placeholder="请输入闪购价【必填项】" id="kill_price" name="kill_price" class="form-control">
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">闪购总数量：</span>
	                <input type="text" style="padding-left:10px;" value="<!--{$seckill_array.max_sale_amount|default:''}-->" placeholder="请输入闪购总数量【必填项】" id="max_sale_amount" name="max_sale_amount" class="form-control">
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">闪购日期：</span>
	                <span style="padding-left:10px;" class="input-group-radio">
	                    <div>
	                        <input type="text" value="<!--{$seckill_array.startDate|default:''}-->" style="width:180px;" name="startDate" readonly="" id="startDate" >
	                        ～
	                        <input type="text" value="<!--{$seckill_array.endDate|default:''}-->" style="width:180px;" name="endDate" readonly="" id="endDate" >
	                        <input type="hidden" name="startTime" id="startTime" value="1">
	                    </div>
	                </span>
	            </div>
	            
	            <div class="input-group input-group-lg">
	                <span class="input-group-addon">使用状态：</span>
	                <span style="padding-left:10px;" class="input-group-radio">
						<!--{if isset($seckill_array)}-->
	                        <input type="radio" name="useFlg" value="1" <!--{if $seckill_array.useFlg == 1}--> checked="checked" <!--{/if}-->>&nbsp;启用
	                        <input type="radio" name="useFlg" value="0" <!--{if $seckill_array.useFlg == 0}--> checked="checked" <!--{/if}-->>&nbsp;禁用
                        <!--{else}-->
	                        <input type="radio" name="useFlg" value="1" checked="checked">&nbsp;启用
	                        <input type="radio" name="useFlg" value="0">&nbsp;禁用
                        <!--{/if}-->
	                </span>
	            </div>

            </form>

        </div>

    </div>

    <div class="bottom_fixbox" >
        <div class="rectbox tac">

            <input type="button" class="btn" onclick="S.edit.check();" value="保存">
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭">
        </div>
    </div>

</div>

<script type="text/javascript">

$('#startDate').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,});
$('#endDate').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,});

var S = {

    kill_id: <!--{$seckill_array.kill_id|default:0}-->,

    product_code: "<!--{$seckill_array.product_code|default:''}-->",

    goods: {

        search: function() {

            var product_code = E.trim($("#product_code").val());
            if (product_code == ""){
                E.alert("请输入商品编号");
            } else if (S.product_code != product_code) {
                E.ajax_get({
                    url: "/invokingAjax-backend/goods/goods.ajax?operFlg=1",
                    data: {
                        product_code: product_code
                    },
                    call: "S.goods.result"
                });
            }

        },

        result: function( o ) {
            if (o.code == 200) {
                $("#product_code").val(o.data.product_code);
                $("#salePrice").text(o.data.goods_price);
                $("#goodsName").text(o.data.goods_name);
                S.product_code = o.data.product_code;
            } else {
                E.alert(o.message);
                $("#product_code").val(S.product_code);
            }

        }

    },

    edit: {

        dt: "",

        check: function() {

            this.dt = E.getFormValues("s_form");
            var error_msg = "";

            if (E.isEmpty(this.dt.product_code))
                error_msg += "闪购商品编号不能为空<br>";

            if (!E.isMoney(this.dt.kill_price) || this.dt.kill_price < 0)
                error_msg += "闪购价必须大于等于0的数字<br>";

            if (!E.isInt(this.dt.max_sale_amount) || this.dt.max_sale_amount <= 0)
                error_msg += "闪购总数量必须是大于0的整数<br>";

            if (E.isEmpty(this.dt.startDate) || E.isEmpty(this.dt.endDate))
                error_msg += "闪购开始结算日期不能为空<br>";
            else if (this.dt.startDate > this.dt.endDate)
                error_msg += "开始日期不能大于结束日期<br>";

            if (this.dt.startTime == 0)
                error_msg += "请选择闪购开始时间<br>";

            if (error_msg != "") {
                E.alert(error_msg);
            } else {
                E.confirm("您确认要保存该闪购活动吗？", "S.edit.execute");
            }

        },

        execute: function() {

            E.loadding.open("正在保存闪购活动，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/promotion/seckill.ajax?operFlg=2",
                data: this.dt,
                call: "S.edit.result"
            });

        },

        result: function( o ) {

            E.loadding.close();

            if (o.code == 200) {
                E.opener("seckill.load");
                if (S.kill_id == 0) {
                    E.alert(o.message, 2, {call: "E.refresh"});
                } else {
                    E.alert(o.message, 2, {call: "E.closeWindows"});
                }
            } else {
                E.alert(o.message);
            }

        }

    }

};

$(document).ready(function() {

    /**
     * 绑定商品编号回车事件
     */
    $("#product_code").keypress(function (e){
        if(e.keyCode == 13){
            S.goods.search();
        }
    });

});

</script>

</body>
</html>